package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.SellOrderBean;
import com.project.mapper.IOutOrderInfoMapper;
import com.project.mapper.ISellOrderMapper;
import com.project.service.ISellCarService;
import com.project.service.ISellOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

/**
 * 销售订单实现类
 */
@Service
@Transactional
public class SellOrderServiceImpl implements ISellOrderService {
    @Autowired
    private ISellOrderMapper sellOrderMapper;
    @Autowired
    private IOutOrderInfoMapper outOrderInfoMapper;
    @Override
    public IPage<SellOrderBean> cutSellOrderByItem(Integer pageNO, String clientName, LocalDate startDate, LocalDate endDate) {
        QueryWrapper<SellOrderBean> qw=new QueryWrapper<>();
        if (clientName !=null && clientName.length() !=0){
            qw.like("s_clientName",clientName);
        }
        if (startDate !=null){
            qw.ge("s_date",startDate);
        }
        if (endDate !=null){
            qw.le("s_date",endDate);
        }
        return sellOrderMapper.selectPage(new Page<>(pageNO,3),qw);
    }

    @Override
    public SellOrderBean findSellOrderById(Integer sellOrderId) {
        SellOrderBean sellOrderObj=sellOrderMapper.selectById(sellOrderId);
        sellOrderObj.setOutOrderInfoList(outOrderInfoMapper.findSellOrderInfoById(sellOrderId));
        return sellOrderObj;
    }
}
